//
//  FoundViewController.swift
//  KkmhSwift
//
//  Created by tenltrs on 2018/10/26.
//  Copyright © 2018 Tenltrs. All rights reserved.
//

import UIKit

class FoundViewController: BaseViewController,TopSwitchViewDelegate,SGPageContentScrollViewDelegate{
    
    private var genderButton : UIButton!
    
    private var titleView : TopSwitchView!
    
    private var searchButton : UIButton!
    
    private var contentView : SGPageContentScrollView!
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        initNav()
        
        initMain()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationItem.nn_backgroundAlpha=0
        
        
    }
    
    func initNav() {
        
        //创建左侧按钮
        genderButton = UIViewTool.mas_button(title: nil, image:App_Gender==1 ? "ic_switch_boy_white_28x28_" : "ic_switch_girl_white_28x28_", backgroundImage: nil, titleColor: nil, fontSize: nil)
        genderButton.size=CGSize(width: 36, height: 40)
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: genderButton)
        
        titleView = TopSwitchView.init(frame: CGRect(x: 0, y: 0, width: 91, height: 28), backgroundImage: UIImage(named: "ic_nav_bg_white_91x28_")!, sliderImage: UIImage(named: "ic_discover_nav_cute_44x26_")!, titles: ["推荐","分类"], fontColor: UIColor.white, selectFontColor: UIColor.NavColor, defaultSelect: 0)
        titleView.delegate=self
        navigationItem.titleView=titleView
        
        //创建右侧按钮
        searchButton = UIViewTool.mas_button(title: nil, image:"ic_search_white_28x28_", backgroundImage: nil, titleColor: nil, fontSize: nil)
        searchButton.size=CGSize(width: 36, height: 40)
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(customView: searchButton)
    }
    
    func initMain(){
        
        let recommend = FoundRmController()
        recommend.view.backgroundColor=UIColor.white
        let classify = FoundClassifyController()
        classify.view.backgroundColor=UIColor.orange
        
        contentView = SGPageContentScrollView.init(frame: view.bounds, parentVC: self, childVCs: [recommend,classify])
        contentView.delegatePageContentScrollView=self
        contentView.isAnimated=true
        contentView.setPageContentScrollViewCurrentIndex(0)
        view.addSubview(contentView)
    }
    
    func pageContentScrollView(_ pageContentScrollView: SGPageContentScrollView!, index: Int) {
        
        titleView.on=index==1
    }
    
    func selectActionWithIndex(index: NSInteger) {
        contentView.setPageContentScrollViewCurrentIndex(index)
    }
}
